package com.hinnotek.amoeba.viewmodels


import androidx.lifecycle.viewModelScope
import com.hinnotek.amoeba.base.BaseBean
import com.hinnotek.amoeba.bean.old.AmibaInstallByIdBean
import com.hinnotek.amoeba.bean.old.AmibaInstallPageByUserIdBean
import com.hinnotek.amoeba.repo.AmibaInstallRepo
import com.lee.common.base.BaseViewModel
import com.lee.common.network.net.StateLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import okhttp3.RequestBody
import javax.inject.Inject

@HiltViewModel
class AmibaInstallViewModel @Inject constructor(private val contractRepo: AmibaInstallRepo) :
    BaseViewModel() {

    val amibaInstallPageByUserIdData = StateLiveData<MutableList<AmibaInstallPageByUserIdBean>>()
    val baseData = StateLiveData<BaseBean>()
    val baseData2 = StateLiveData<BaseBean>()
    val baseData3 = StateLiveData<BaseBean>()
    val amibaInstallByIdData = StateLiveData<AmibaInstallByIdBean>()


    fun getAmibaInstallPageByUserId(integer: Int, pageNo: Int, pageSize: Int): StateLiveData<MutableList<AmibaInstallPageByUserIdBean>> {
        viewModelScope.launch {
            contractRepo.getAmibaInstallPageByUserId(integer,pageNo,pageSize, amibaInstallPageByUserIdData)
        }
        return amibaInstallPageByUserIdData
    }

    fun updateAmibaInstallCompleteState(amibaInstallId: Int) :StateLiveData<BaseBean>{
        viewModelScope.launch {
            contractRepo.updateAmibaInstallCompleteState(amibaInstallId, baseData)
        }
        return baseData
    }

    fun addAmibaInstallContinued(amibaInstallId: Int, continuedMoney: String) :StateLiveData<BaseBean>{
        viewModelScope.launch {
            contractRepo.addAmibaInstallContinued(amibaInstallId,continuedMoney, baseData2)
        }
        return baseData2
    }

    fun getAmibaInstallById(amibaInstallId: Int):StateLiveData<AmibaInstallByIdBean> {
        viewModelScope.launch {
            contractRepo.getAmibaInstallById(amibaInstallId, amibaInstallByIdData)
        }
        return amibaInstallByIdData
    }

    fun addAmibaInstall(requestBody: RequestBody) :StateLiveData<BaseBean>{
        viewModelScope.launch {
            contractRepo.addAmibaInstall(requestBody, baseData3)
        }
        return baseData3
    }
}